<?php

	// TITLE: Purpose_type AUTO MODEL
	// FILE: scaffolding/model/purpose_type.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createPurposeType = function($con, $purposeType) {
		$sql = 'INSERT INTO purpose_type (id, title, description) VALUES (';
		$sql .= $purpose_type->getId() . ', ';
		$sql .= $purpose_type->getTitle() . ', ';
		$sql .= $purpose_type->getDescription() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readPurposeType = function($con, $id) {
		$sql = 'SELECT * FROM purpose_type WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$purposeType = new PurposeType();
			$purposeType->setId(result[0]);
			$purposeType->setTitle(result[1]);
			$purposeType->setDescription(result[2]);
		} else {
			$purposeType = false;
		}
		return $purposeType;
	};

	$updatePurposeType = function($con, $purposeType) {
		$sql = 'UPDATE purpose_type SET ';
		$sql .= 'id = ' . $purpose_type->getId() . ', ';
		$sql .= 'title = ' . $purpose_type->getTitle() . ', ';
		$sql .= 'description = ' . $purpose_type->getDescription() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deletePurposeType = function($con, $id) {
		$sql = 'DELETE FROM purpose_type WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listPurposeType = function($con) {
		$sql = 'SELECT * FROM purpose_type';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$purposeTypes = array();
			while ($result = mysqli_fetch_array($results)) {
				$purposeType = new PurposeType();
				$purposeType->setId(result[0]);
				$purposeType->setTitle(result[1]);
				$purposeType->setDescription(result[2]);
				$purposeTypes[] = purposeType;
			}// end while
		} else {
			$purposeTypes = false;
		}
		return $purposeTypes;
	};

